﻿using System.Collections.Generic;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using Avalonia.ReactiveUI;
using Avalonia.Threading;
using MilkTeaMachine.OfflineClient.ViewModels;
using ReactiveUI;

namespace MilkTeaMachine.OfflineClient.Views;

public partial class AutoRunningPressKeyUserControl : ReactiveUserControl<AutoRunningPressKeyViewModel>
{
    public AutoRunningPressKeyViewModel ViewModelLocal => ViewModel!;

    public AutoRunningPressKeyUserControl()
    {
        AvaloniaXamlLoader.Load(this);
        this.WhenActivated(_ => { });
    }

    private Button? _lastClickedButton;

    private void Button_OnClick(object? sender, RoutedEventArgs e)
    {
        if (sender is not Button button) return;
        Dispatcher.UIThread.Invoke(() =>
        {
            button.Foreground = new SolidColorBrush(Colors.PaleVioletRed);
            if (_lastClickedButton != null)
            {
                if(_lastClickedButton == button) return;
                _lastClickedButton.Foreground = new SolidColorBrush(Colors.Black);
            }
            _lastClickedButton = button;
        });
    }
}